﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Configuration;
using System.Reflection;
using MediaBrowser.Library;
using System.Xml.Serialization;
using MediaBrowser.Library.Logging;
using MediaBrowser.Library.Plugins.Configuration;
using Microsoft.MediaCenter;
using Microsoft.MediaCenter.UI;

namespace Chocolate
{
    public class TheSettings: ModelItem
    {
        //settings to save
        
        [Description("First Load")]
        public bool FirstLoad
        { get; set; }
        
    }
    public static class Settings
    {

        public static string SettingPath = "SimplicitySettings.xml";
        private static TheSettings _instance;
        public static TheSettings Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new TheSettings();
                    InitSettings();
                }
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }


        public static void InitSettings()
        {
            //SettingPath = Path.GetFullPath();
            if (File.Exists(SettingPath))
            {
                LoadSettings();
            }
            else
            {
                Instance.FirstLoad = true;
                SaveSettingsFile();
            }
        }

        private static void LoadSettings()
        {
            XmlSerializer ser = new XmlSerializer(typeof(TheSettings));

            TextReader reader = new StreamReader(SettingPath);
            Instance = (TheSettings)ser.Deserialize(reader);
            reader.Close();
        }

        public static void SaveSettingsFile()
        {
            XmlSerializer ser = new XmlSerializer(typeof(TheSettings));

            TextWriter writer = new StreamWriter(SettingPath);
            ser.Serialize(writer, Settings.Instance);
            writer.Close();

        }

        

        
    }
}
